package com.hnx.admin.security.handler;


import com.hnx.admin.api.http.HttpStatusAPI;
import com.hnx.admin.security.api.LogoutHandler;
import com.hnx.admin.utils.MessageUtil;
import com.hnx.admin.utils.ResponseUtil;
import com.hnx.admin.web.json.ResultJson;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/*
创建人： 倔强的头发
创建时间：2025/5/17
功能描述:

*/
@Component
@RequiredArgsConstructor
public class LogoutSuccessHandlerImpl  implements LogoutSuccessHandler, HttpStatusAPI {
    private final LogoutHandler logoutHandler;
    private static final String LOGOUT_SUCCESS = "user.logout.success";
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        logoutHandler.handler();
        ResponseUtil.write(response, com.alibaba.fastjson2.JSON.toJSONString(ResultJson.success(MessageUtil.message(LOGOUT_SUCCESS))));
    }
}
